<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item label="项目名称">
        <el-input
          v-model="dataForm.projectName"
          placeholder="项目名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="任务名称">
        <el-input
          v-model="dataForm.taskName"
          placeholder="任务名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="任务状态">
        <el-input
          v-model="dataForm.taskStatus"
          placeholder="任务状态"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('generator:businesstask:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <el-button
          v-if="isAuth('business:mytask:delete')"
          type="danger"
          @click="deleteHandle()"
          :disabled="dataListSelections.length <= 0"
          >批量删除</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      ></el-table-column>
      <!-- <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="任务id">
      </el-table-column>-->
      <!-- <el-table-column
        prop="projectId"
        header-align="center"
        align="center"
        label="项目id">
      </el-table-column>-->
      <el-table-column
        prop="beginTime"
        header-align="center"
        align="center"
        label="计划开始时间"
      ></el-table-column>
      <el-table-column
        prop="endTime"
        header-align="center"
        align="center"
        label="计划结束时间"
      ></el-table-column>
      <el-table-column
        prop="taskName"
        header-align="center"
        align="center"
        label="任务名称"
      ></el-table-column>
      <el-table-column
        prop="taskDescription"
        header-align="center"
        align="center"
        label="任务描述"
      ></el-table-column>
      <el-table-column
        prop="dataListing"
        header-align="center"
        align="center"
        label="资料清单"
      ></el-table-column>
      <el-table-column
        prop="allocateUserNames"
        header-align="center"
        align="center"
        label="分配人"
      ></el-table-column>
      <el-table-column
        prop="headUserName"
        header-align="center"
        align="center"
        label="负责人"
      ></el-table-column>
      <el-table-column
        prop="auditUserName"
        header-align="center"
        align="center"
        label="审核人"
      ></el-table-column>
      <el-table-column
        prop="taskStatus"
        header-align="center"
        align="center"
        label="当前状态"
      >
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{
            taskStatusList[scope.row.taskStatus]
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <!-- <el-button
            v-if="isAuth('business:mytask:update')"
            type="text"
            size="small"
            @click="addOrUpdateHandle(scope.row.taskId)"
            >修改</el-button
          > -->
          <!-- <el-button
            v-if="isAuth('business:mytask:delete')"
            type="text"
            size="small"
            @click="deleteHandle(scope.row.taskId)"
            >删除</el-button
          > -->
          <el-button
            type="text"
            size="small"
            @click="infoHandle(scope.row.taskId)"
            >详情</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="queryHandle(scope.row.taskId)"
            >进度</el-button
          >
          <el-button
            type="text"
            a
            size="small"
            @click="dealHandle(scope.row.taskId)"
            >办理</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <info-select
      v-if="addOrUpdateVisible"
      ref="infoSelect"
      @refreshDataList="getDataList"
    ></info-select>
    <!--办理 -->
    <deal-add
      v-if="dealAddVisible"
      ref="dealAdd"
      @refreshDataList="getDataList"
    ></deal-add>
  </div>
</template>

<script>
import InfoSelect from "./mytaskdeil";
import DealAdd from "./taskdeal";
export default {
  data() {
    return {
      dataForm: {
        key: "",
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      dealAddVisible: false,
      taskStatusList: {
        1: "进行中",
        2: "已提交",
        3: "延期",
        4: "已完成",
      },
    };
  },
  activated() {
    this.getDataList();
  },
  components: {
    InfoSelect,
    DealAdd,
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/business/task/my-task-list"),
        method: "get",
        params: this.$http.adornParams({
          pageNum: this.pageIndex,
          pageSize: this.pageSize,
          key: this.dataForm.key,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    //详情
    infoHandle(id) {
      this.addOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.infoSelect.init(id);
      });
    },
    // 新增 / 修改
    addOrUpdateHandle(id) {
      var map = {};
      map.id = id;
      this.$router.push({
        name: "business-task-add-or-update",
        params: { taskinfo: map },
      });
    },
    //进度查看
    queryHandle(id) {
      var map = {};
      map.id = id;
      this.$router.push({
        name: "business-looktask",
        params: { taskinfo: map },
      });
    },
    //办理
    dealHandle(id) {
      this.dealAddVisible = true;
      this.$nextTick(() => {
        this.$refs.dealAdd.init(id);
      });
    },
    // 删除
    deleteHandle(id) {
      var ids = id
        ? [id]
        : this.dataListSelections.map((item) => {
            return item.taskId;
          });
      this.$confirm(
        `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl("business/task/delete"),
          method: "post",
          data: this.$http.adornData(ids, false),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.getDataList();
              },
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
  },
};
</script>
